﻿using System.Linq;
using System.Net.Http;
using System.Web.Http.Filters;
using ZLWeb.WebApiEntity;

namespace ZLWeb.WebApiInfrastructure.Filter
{
    public class RandomCodeAtrribute : ActionFilterAttribute
    {
        public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext)
        {
            var RandomCode =
                actionExecutedContext.Request.Headers.Contains("RandomCode")
                    ? actionExecutedContext.Request.Headers.FirstOrDefault(x => x.Key == "RandomCode")
                        .Value.FirstOrDefault()
                    : string.Empty;

            try
            {
                dynamic Content = actionExecutedContext.Response.Content;
                Content.Value.RandomCode = RandomCode;
            }
            catch (System.Exception)
            {
            }
            
        }
    }
}